﻿using System;
using System.Collections.Generic;
using Wicture.EPC.OnlineQueryProxy.Agents;

namespace Wicture.EPC.OnlineQueryProxy
{
    public class RandomStrategyScheduler : IScheduler
    {
        public string Strategy { get; } = "Random";

        private static Random random = new Random(9999);

        /// <summary>
        /// 完全随机。
        /// 注意：查询结果返回前，不再路由到同一台代理服务器上。
        /// </summary>
        /// <param name="agents"></param>
        /// <returns></returns>
        public Agent GetNext(List<Agent> agents)
        {
            var agent = agents[random.Next(0, agents.Count)];

            // 如果随机到繁忙的服务器，重新获取。
            return agent.IsBusy ? GetNext(agents) : agent;
        }
    }
}
